import http from 'http/http';

const Global = {};
Global.online = true;

if (Global.online) {
  Global.BASE_URL = 'http://www.stypt.cn/website-su-admin-api';
} else {
  Global.BASE_URL = 'http://localhost:8100';
}

const Method = {
  GET: 'get',
  POST: 'post',
  PUT: 'put'
};

// 登录
export const login = ({ username, password }) => {
  return http({
    method: Method.POST,
    url: Global.BASE_URL + '/user/login',
    data: {
      name: username,
      password
    }
  });
};

// 退出登录
export const logout = () => {
  return http({
    method: Method.GET,
    url: Global.BASE_URL + '/user/logout'
  });
};

// 注册
export const register = ({ username, password }) => {
  return http({
    method: Method.POST,
    url: Global.BASE_URL + '/user/register',
    data: {
      name: username,
      password
    }
  });
};

// 修改密码
export const modifyPassword = ({ username, oldPassword, password }) => {
  return http({
    method: Method.POST,
    url: Global.BASE_URL + '/user/modify/password',
    data: {
      name: username,
      password: oldPassword,
      newPassword: password
    }
  });
};

// 获取推广位列表
export const getPromotionPositionList = ({ name, pageSize, pageNum }) => {
  return http({
    method: Method.POST,
    url: Global.BASE_URL + '/pdd/get/pid/list',
    data: {
      pidName: name,
      page: pageNum,
      size: pageSize
    }
  });
};

// 添加推广位
export const addPromotionPosition = ({ name }) => {
  return http({
    method: Method.POST,
    url: Global.BASE_URL + '/pdd/create/pid/',
    data: {
      pidName: name
    }
  });
};

// 获取订单列表
export const getOrderList = ({
  pageSize,
  pageNum,
  promotionPositionId,
  startDate,
  endDate
}) => {
  return http({
    method: Method.POST,
    url: Global.BASE_URL + '/pdd/get/order/list',
    data: {
      page: pageNum,
      size: pageSize,
      id: promotionPositionId,
      startDate,
      endDate
    }
  });
};

// 获取提现列表
export const getWithdrawList = ({
  pageSize,
  pageNum,
  name,
  account,
  startDate,
  endDate
}) => {
  return http({
    method: Method.POST,
    url: Global.BASE_URL + '/withdraw/list',
    data: {
      page: pageNum,
      size: pageSize,
      zfbName: name,
      telNumber: account,
      startDate,
      endDate
    }
  });
};

// 提现
export const withdraw = ({ id, status }) => {
  return http({
    method: Method.POST,
    url: Global.BASE_URL + '/withdraw/update/status',
    data: {
      id,
      status
    }
  });
};

// 错误日志 提现列表
export const getErrWithdrawList = ({
  pageSize,
  pageNum,
  name,
  account,
  startDate,
  endDate
}) => {
  return http({
    method: Method.POST,
    url: Global.BASE_URL + '/err/log/list',
    data: {
      page: pageNum,
      size: pageSize,
      zfbName: name,
      telNumber: account,
      startDate,
      endDate
    }
  });
};
